﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace JPGResizer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private int _PageIndex;
        public int PageIndex
        {
            set
            {
                if (value > 4)
                {
                    InitializePageIndex();
                }
                else if (value < 1)
                {
                    InitializePageIndex();
                }
                else
                {
                    _PageIndex = value;
                    if (_PageIndex == 1)
                    {
                        this.Previous.Visibility = System.Windows.Visibility.Collapsed;
                    }
                    else
                    {
                        this.Previous.Visibility = System.Windows.Visibility.Visible;
                    }
                }
                this.mainFrame.Navigate(new Uri(string.Format("Pages/Page{0}.xaml",_PageIndex), UriKind.Relative));
            }
            get
            {
                return _PageIndex;
            }
        }

        private void InitializePageIndex()
        {
            this.PageIndex = 1;
            Helper.ValueHelper.CurrentValues.ClearCache();
        }
        public MainWindow()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
        }

        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            InitializePageIndex();
        }

        private void Next_Click(object sender, RoutedEventArgs e)
        {
            this.PageIndex++;
        }

        private void Previous_Click(object sender, RoutedEventArgs e)
        {
            this.PageIndex--;
        }
    }
}
